package com.legolas.provider.dao;

import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: Legolas
 * Date: 2017/7/16 0016
 */
@Repository
public interface GoodsDao {

    @Insert("insert into goods (name,stock) value (#{name},#{stock})")
    int addGoods(@Param("name") String name, @Param("stock") Integer stock);

    @Select("select stock from goods where id = #{id}")
    int queryStockById(Integer id);

    @Update("update goods set stock = stock-1 where id = #{id} and stock > 0")
    int minusStock(Integer id);

    @Update("update goods set stock = stock+5 where id = #{id}")
    int addStock(Integer id);

    @Select("select id,name,stock from goods")
    @ResultType(java.util.HashMap.class)
    List<Map<String, Object>> listGoods();


}
